package com.projects.android.dto;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class CityDTO {
	private int ID;
	private String Name;
	private ArrayList<DistrictDTO> Districts;
	
	public String toString(){
		return Name;
	}
	
	public void initObject(JSONObject data){
		try {
			ID = Integer.valueOf(data.getString("ID"));
			Name = data.getString("Name");
			Districts = new ArrayList<DistrictDTO>();
			JSONArray arrData = new JSONArray(data.getString("Districts"));
			// Loop for all reveived objects
			for (int i = 0; i < arrData.length(); i++) {
				JSONObject dataChild = (JSONObject) arrData.get(i);
				DistrictDTO dto = new DistrictDTO();
				dto.initObject(dataChild);
				Districts.add(dto);
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			Log.e("Init CityDTO", e.toString());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			Log.e("Init CityDTO", e.toString());
		}
	}
	
	public int getID() {
		return ID;
	}
	public void setID(int iD) {
		ID = iD;
	}
	public String getName() {
		return Name;
	}
	public void setName(String name) {
		Name = name;
	}
	public ArrayList<DistrictDTO> getDistricts() {
		return Districts;
	}
	public void setDistricts(ArrayList<DistrictDTO> districts) {
		Districts = districts;
	}
}
